export default {
    namespaced: true,
    state:()=>({
      address:JSON.parse(uni.getStorageSync('address') || '{}'),
      token:uni.getStorageSync('token') || '',
      //用户信息对象
      userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}' )
    }),
 
    //方法
    mutations:{
      //持久化储存address
      saveAddressToStorage(state){
        uni.setStorageSync('address',JSON.stringify(state.address))
      },
      //持久化储存token
      saveTokenToStorage(state){
         uni.setStorageSync('token',state.token)
      },
      //更新token
      updateToken(state,token){
        state.token=token
        this.commit('m_user/saveTokenToStorage')
      },
      //更新地址
      updateAddress(state,address){
         state.address =address
         this.commit('m_user/saveAddressToStorage')
      },
      //更新用户信息
      updateUserInfo(state,userinfo){
         state.userinfo = userinfo
         this.commit('m_user/saveUserInfoToStorage')
      },
      //更新用户昵称
      updateUserInfoSickname(state,nickName){
        state.userinfo.nickName=nickName
         this.commit('m_user/saveUserInfoToStorage')
      },
      //更新用户头像
      updateUserInfoAvatarUrl(state,avatarUrl){
        state.userinfo.avatarUrl=avatarUrl
        this.commit('m_user/saveUserInfoToStorage')
      },
      //保存用户信息
      saveUserInfoToStorage(state){
        uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
      }
    },
    //计算
    getters:{
      addressStr(state){
        if(!state.address.provinceName) return ''
        return state.address.provinceName + state.address.cityName +state.address.countyName + state.address.detailInfo
      }
    }
}